﻿using UnityEngine;

namespace Combat
{
    public class MultipleBulletLauncher : MonoBehaviour, ILauncher
    {
        [SerializeField] private BulletData bulletData;

        [SerializeField] private float spreadDegreeRange = 35f;
        [SerializeField] private int bulletsPerShot = 3;
        
        
        public void Fire(Vector3 muzzlePosition, Vector3 atDirection, Vector3 atPosition, Team team)
        {
            float angleUnit = spreadDegreeRange / bulletsPerShot;
            float angle = -spreadDegreeRange / 2f;
            
            for (int i = 0; i < bulletsPerShot; i++)
            {
                Vector3 direction = Quaternion.Euler(0, 0, angle) * atDirection;
                angle += angleUnit;
                BulletsPool.Instance.CreateBullet(team, bulletData, muzzlePosition, direction);
            }
        }
    }
}